package cn.g31010.sip.util
{
	import flash.display.DisplayObject;
	
	import mx.containers.TitleWindow;
	import mx.controls.TextArea;
	import mx.core.Application;
	import mx.events.CloseEvent;
	import mx.logging.Log;
	import mx.managers.PopUpManager;
	
	public class Logger
	{
		private static var text:TextArea;
		private static var tw:TitleWindow;
		public static var DEBUG:int=0;
		public static var INFO:int=1;
		public static var ERROR:int=2;
		
		public static var level:int=3;
		public function Logger()
		{
		}
		
		public static function debug(str:String):void{
			if(level>DEBUG)
				return;
			if(tw==null){
				tw = new TitleWindow();
				tw.width=400;
				tw.height=300;
				tw.showCloseButton=true;
				tw.addEventListener(CloseEvent.CLOSE,function(e:CloseEvent):void{
					mx.managers.PopUpManager.removePopUp(tw);
				});
				tw.x=Application.application.width-tw.width;
				tw.y=0;
				text=new TextArea();
				text.width=tw.width-28;
				text.height=tw.height-48;
				tw.addChild(text);
				mx.managers.PopUpManager.addPopUp(tw,Application.application as DisplayObject,false);
				//mx.managers.PopUpManager.centerPopUp(tw);
			}
			text.text+="DEBUG "+str+"\n";
			trace("DEBUG "+str);
		}
		
		public static function info(str:String):void{
			if(level>INFO)
				return;
			if(tw==null){
				tw = new TitleWindow();
				tw.width=400;
				tw.height=300;
				tw.showCloseButton=true;
				tw.addEventListener(CloseEvent.CLOSE,function(e:CloseEvent):void{
					mx.managers.PopUpManager.removePopUp(tw);
				});
				tw.x=Application.application.width-tw.width;
				tw.y=0;
				text=new TextArea();
				text.width=tw.width-28;
				text.height=tw.height-48;
				tw.addChild(text);
				mx.managers.PopUpManager.addPopUp(tw,Application.application as DisplayObject,false);
				//mx.managers.PopUpManager.centerPopUp(tw);
			}
			text.text+="INFO "+str+"\n";
			trace("INFO "+str);
		}
		
		public static function error(str:String):void{
			if(level>ERROR)
				return;
				if(tw==null){
				tw = new TitleWindow();
				tw.width=400;
				tw.height=300;
				tw.showCloseButton=true;
				tw.addEventListener(CloseEvent.CLOSE,function(e:CloseEvent):void{
					mx.managers.PopUpManager.removePopUp(tw);
				});
				tw.x=Application.application.width-tw.width;
				tw.y=0;
				text=new TextArea();
				text.width=tw.width-28;
				text.height=tw.height-48;
				tw.addChild(text);
				mx.managers.PopUpManager.addPopUp(tw,Application.application as DisplayObject,false);
				//mx.managers.PopUpManager.centerPopUp(tw);
			}
			text.text+="ERROR "+str+"\n";
			trace("ERROR "+str);
			
		}
	}
}